#ifndef _MINI_CRT_H__
#define _MINI_CRT_H__

#include <stdarg.h>
#include <sys/types.h>

typedef int FILE;

#define NULL (0)
#define __in__
#define __out__
#define __in_out__

#define stdin  ((FILE*)0)
#define stdout ((FILE*)1)
#define stderr ((FILE*)2)
#define EOF    (-1)

//init
int mini_crt_heap_init();
int mini_crt_io_init();

//memory
void* malloc(const int size);
void free(void* ptr);
void* memset(void* s, int c, size_t n);
int memcmp(const void* s1, const void* s2, size_t n);

//io
FILE* fopen(const char* path, const char* mode);
size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream);
int fclose(FILE* fp);
int fseek(FILE* stream, long offset, int whence);

int fputc(int c, FILE* stream);
int fputs(const char* s, FILE* stream);

int sprintf(FILE* stream, const char* format, ...);//todo
int printf(const char* format, ...);
int vprintf(const char* format, va_list ap);
int vsprintf(char* str, const char* format, va_list ap);//todo
void perror(const char* s);

//string
int strcmp(const char* s1, const char* s2);
size_t strlen(const char* s);
char* strcpy(char* dest, const char* src);
int atoi (const char* ptr);
int itoa(const int i, int base, int aux, char* __out__ buf);

//syscall
void exit(int exit_code);
void* brk(void* end_data_segment);
long open(const char* path, int flags, int mode);
int close(FILE* fd);
ssize_t read(/*int*/FILE* fd, void* buf, size_t size);
ssize_t write(/*int*/FILE* fd, const void* buf, size_t size);
int seek(/*int*/FILE* fd, int offset, int mode);

//debug
char* get_env(char** argv, const char* key);
int debug_init(char** argv);

#endif
